﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Sector7.Medical.EntityType;
using Sector7.Framework.DB;
using Sector7.Medical.DAO.Standard;
using Sector7.Medical.DAO;
using Sector7.Framework.DAO.Standard;
using Sector7.Framework.Consts;
using Sector7.Medical.Enums;

namespace Sector7.Medical.Services
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的类名“BusinessService”。
    public class BusinessService : IBusinessService
    {
        #region /// ChargeRecord

        /// <summary>
        /// 添加费用信息
        /// </summary>
        /// <param name="chargeRecord">费用信息</param>
        /// <returns></returns>
        public int AddChargeRecord(M7_ChargeRecord chargeRecord)
        {
            object result = DAOFactory.GetDAO<ChargeRecordDAO>().Create(chargeRecord);
            return Convert.ToInt32(result);
        }

        #endregion

        #region ///Registry Record

        /// <summary>
        /// 获取一天的挂号记录
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public List<M7_RegistryRecord> GetRegistryRecoredListInOneDay(DateTime date)
        {
            return DAOFactory.GetDAO<RegistryRecordDAO>().GetRegistryRecoredListInOneDay(date);
        }

        /// <summary>
        /// 添加挂号信息
        /// </summary>
        /// <param name="patient">挂号信息</param>
        /// <returns></returns>
        public int AddRegistryRecord(M7_RegistryRecord registryRecord)
        {
            object result = DAOFactory.GetDAO<RegistryRecordDAO>().Create(registryRecord);
            return Convert.ToInt32(result);
        }

        #endregion

        #region /// Patient
        /// <summary>
        /// 添加病人信息
        /// </summary>
        /// <param name="registryRecord">病人信息</param>
        /// <returns></returns>
        public int AddPatient(M7_Patient patient)
        {
            int result = 0;
            result = Convert.ToInt32(DAOFactory.GetDAO<CitizenDAO>().Create(patient));
            result += Convert.ToInt32(DAOFactory.GetDAO<PatientDAO>().Create(patient));
            return (result == 2) ? C_ErrorCode.ERR_DB_SUCCESS : C_ErrorCode.ERR_DB_FAILURE;
        }

        /// <summary>
        /// 根据登记号获取病人信息
        /// </summary>
        /// <param name="registryNoType">登记号类型</param>
        /// <param name="registryNo">登记号</param>
        /// <returns></returns>
        public M7_Patient GetPatientByRegistryNo(RegistryNoType registryNoType, object registryNo)
        {
            return DAOFactory.GetDAO<PatientDAO>().ReadByRegistryNo(registryNoType, registryNo);
        }
        #endregion

        #region ///MedicalRecord
        /// <summary>
        /// 添加电子病历信息
        /// </summary>
        /// <param name="medicalRecord"></param>
        /// <returns></returns>
        public int AddMedicalRecord(M7_MedicalRecord medicalRecord)
        {
            object result = DAOFactory.GetDAO<MedicalRecordDAO>().Create(medicalRecord);
            return Convert.ToInt32(result);
        }

        /// <summary>
        /// 根据人员信息编码和状态获取电子病历信息
        /// </summary>
        /// <param name="citizen"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public List<M7_MedicalRecord> GetMedicalRecordByCitizenAndStatus(string citizen, int status)
        {
            return DAOFactory.GetDAO<MedicalRecordDAO>().ReadAll(citizen, status);
        }

        public List<M7_MedicalRecord> GetRecentTenMedicalRecordList(string citizenId)
        {
            return DAOFactory.GetDAO<MedicalRecordDAO>().ReadAll(citizenId);
        }
        #endregion

        #region ///Recipe
        /// <summary>
        /// 添加处方信息
        /// </summary>
        /// <param name="recipe"></param>
        /// <returns></returns>
        public int AddRecipe(M7_Recipe recipe)
        {
            object result = DAOFactory.GetDAO<RecipeDAO>().Create(recipe);
            return Convert.ToInt32(result);
        }

        /// <summary>
        /// 根据电子病历编号和单据状态获取所有处方单信息
        /// </summary>
        /// <returns></returns>
        public List<M7_Recipe> GetPatientRecipeListByEmrIdAndStatus(long emrId, int status)
        {
            return DAOFactory.GetDAO<RecipeDAO>().ReadAll(emrId, status);
        }
        #endregion
    }
}
